<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学院" prop="college">
        <el-input
          v-model="queryParams.college"
          placeholder="请输入学院"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任课教师" prop="tName">
        <el-input
          v-model="queryParams.tName"
          placeholder="请输入任课教师"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="查卷教师" prop="supName">
        <el-input
          v-model="queryParams.supName"
          placeholder="请输入查卷教师"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="授课学期" prop="schoolSemester">
        <el-input
          v-model="queryParams.schoolSemester"
          placeholder="格式：2020-2021第1学期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业班级" prop="testClass">
        <el-input
          v-model="queryParams.testClass"
          placeholder="请输入专业班级"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="课程名称" prop="courseName">
        <el-input
          v-model="queryParams.courseName"
          placeholder="请输入课程名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['course:testReview:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['course:testReview:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['course:testReview:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['course:testReview:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-tooltip class="item" effect="dark" content="每张表由查卷人分试卷填写，一个班（或合班）一门课程一份表。" placement="top">
          <el-button
            type="info"
            plain
            icon="el-icon-info"
            size="mini"
          >注意事项</el-button>
        </el-tooltip>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="testReviewList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" width="60" align="center">
        <template slot-scope="scope">
          {{scope.$index + 1}}
        </template>
      </el-table-column>
      <el-table-column label="学院" align="center" prop="college" />
      <el-table-column label="任课教师" align="center" prop="tName" />
      <el-table-column label="查卷教师" align="center" prop="supName" />
      <el-table-column label="授课学期" align="center" prop="schoolSemester" />
      <el-table-column label="专业班级" align="center" prop="testClass" />
      <el-table-column label="课程名称" align="center" prop="courseName" />
      <el-table-column label="试卷复查评价" width="150" align="center" prop="attendEvalFlag">
        <template slot-scope="scope">
          <div v-if="scope.row.reviewEvalFlag === '0'">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-circle-plus-outline"
              @click="toReviewEval(scope.row)" 
              >去评价</el-button
            >
          </div>
          <div v-else-if="scope.row.reviewEvalFlag === '1'">
            <el-tag type="success">已评价</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="登记和查看" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit-outline"
            @click="testReviewMistake(scope.row)"
            >成绩错误登记</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="openTestReviewTable(scope.$index)"
            >查看试卷复查表</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['course:testReview:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['course:testReview:remove']"
          >删除</el-button>
          
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改本科试卷复查对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>
      <el-row :gutter="15">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-col :span="11">
            <el-form-item label="学院" prop="college">
              <el-input v-model="form.college" placeholder="请输入学院" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="任课教师" prop="tName">
              <el-input v-model="form.tName" placeholder="请输入任课教师" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="教师工号" prop="tNum">
              <span slot="label">
                <el-tooltip content="可在职工管理中查询，建议先填写其他重要信息保存后再补充">
                <i class="el-icon-info"></i>
                </el-tooltip>
                教师工号
              </span>
              <el-input
                v-model="form.tNum"
                placeholder="建议输入教师工号"
                oninput ="value=value.replace(/[^0-9.]/g,'')"
                :maxlength="11"
                clearable
                :style="{ width: '100%' }"
                />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="出题教师" prop="tQuestion">
              <el-input v-model="form.tQuestion" placeholder="请输入出题教师" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="阅卷教师" prop="tReading">
              <el-input v-model="form.tReading" placeholder="请输入阅卷教师" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="授课学期" prop="schoolSemester">
              <span slot="label">
                <el-tooltip content="输入格式如：2020-2021第1学期">
                <i class="el-icon-info"></i>
                </el-tooltip>
                授课学期
              </span>
              <el-input v-model="form.schoolSemester" placeholder="格式：2020-2021第1学期" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="专业班级" prop="testClass">
              <el-input v-model="form.testClass" placeholder="请输入专业班级" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="课程名称" prop="courseName">
              <el-input v-model="form.courseName" placeholder="请输入课程名称" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="试卷份数" prop="paperNum">
              <el-input v-model="form.paperNum" oninput ="value=value.replace(/[^0-9.]/g,'')" :maxlength="4" placeholder="请输入试卷份数" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="复查人意见" prop="supIdea">
              <el-input v-model="form.supIdea" type="textarea" :autosize="{ minRows: 2 ,maxRows: 4 }" placeholder="请输入复查人意见" />
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 查看试卷复查表 -->
    <el-dialog :title="title" :visible.sync="openTable" width="900px" append-to-body>
      <!-- 添加滚动条 -->
      <el-scrollbar style="height: 750px;">
        <el-descriptions class="margin-top" :model="testReviewTable" title="重庆三峡学院本科试卷复查情况记录表" :column="3" border>
          <template slot="extra">
            {{"填表日期：" + parseTime(testReviewTable.createTime, '{y}-{m}-{d}')}}
          </template>

          <el-descriptions-item>
            <template slot="label">
              学院
            </template>
            {{testReviewTable.college}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              任课教师
            </template>
            {{testReviewTable.tName}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              出题教师
            </template>
            {{testReviewTable.tQuestion}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              阅卷教师
            </template>
            {{testReviewTable.tReading}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              查卷教师
            </template>
            {{testReviewTable.supName}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              授课学期
            </template>
            {{testReviewTable.schoolSemester}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              专业班级
            </template>
            {{testReviewTable.testClass}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              课程名称
            </template>
            {{testReviewTable.courseName}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              试卷份数
            </template>
            {{testReviewTable.paperNum}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              复查人意见
            </template>
            {{testReviewTable.supIdea}}
          </el-descriptions-item>
        </el-descriptions>

        <el-table :data="testReviewTable.testReviewItems" border style="width: 100%">
          <el-table-column label="序号" width="60" align="center">
            <template slot-scope="scope">
              {{scope.$index + 1}}
            </template>
          </el-table-column>

          <el-table-column prop="content" label="评价指标" />
          <el-table-column prop="options" width="380px" label="评价结果选项" />
          <el-table-column prop="mySituation" label="评价结果" align="center" width="80" />
        </el-table>
      </el-scrollbar>
    </el-dialog>
  </div>
</template>

<script>
import { listTestReview, getTestReview, delTestReview, addTestReview, updateTestReview, getTestReviewTable } from "@/api/course/testReview";

export default {
  name: "TestReview",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 本科试卷复查表格数据
      testReviewList: [],
      // 查看本科试卷复查表数据
      testReviewTable: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查看本科试卷复查综合表Modal
      openTable: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        college: null,
        tName: null,
        supName: null,
        schoolSemester: null,
        testClass: null,
        courseName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        college: [
          { required: true, message: "学院不能为空", trigger: "blur" }
        ],
        tName: [
          { required: true, message: "任课教师不能为空", trigger: "blur" }
        ],
        tQuestion: [
          { required: true, message: "出题教师不能为空", trigger: "blur" }
        ],
        tReading: [
          { required: true, message: "阅卷教师不能为空", trigger: "blur" }
        ],
        schoolSemester: [
          { required: true, message: "授课学期不能为空", trigger: "blur" }
        ],
        testClass: [
          { required: true, message: "专业班级不能为空", trigger: "blur" }
        ],
        courseName: [
          { required: true, message: "课程名称不能为空", trigger: "blur" }
        ],
        paperNum: [
          { required: true, message: "试卷份数不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询本科试卷复查列表 */
    getList() {
      this.loading = true;
      listTestReview(this.queryParams).then(response => {
        this.testReviewList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        college: null,
        tName: null,
        tNum: null,
        tQuestion: null,
        tReading: null,
        supName: null,
        schoolSemester: null,
        testClass: null,
        courseName: null,
        paperNum: null,
        supIdea: null,
        reviewEvalFlag: null,
        createBy: null,
        updateBy: null,
        createTime: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加本科试卷复查";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTestReview(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改本科试卷复查";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTestReview(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTestReview(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除本科试卷复查编号为"' + ids + '"的数据项？').then(function() {
        return delTestReview(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('course/testReview/export', {
        ...this.queryParams
      }, `testReview_${new Date().getTime()}.xlsx`)
    },
    /** 去评价按钮操作 */
    toReviewEval(row) {
      const testReviewId = row.id
      this.$router.push({ path: '/course/testReviewEval/toTRE', query: { testReviewId: testReviewId, pageNum: this.queryParams.pageNum } });
    },
    /** 去成绩错误登记表 */
    testReviewMistake(row) {
      const testReviewId = row.id
      const tReading = row.tReading
      this.$router.push({ path: '/course/testReviewMistake/toTRMistake', query: { testReviewId: testReviewId, tReading: tReading, pageNum: this.queryParams.pageNum } });
    },
    /** 查看试卷复查表 */
    openTestReviewTable(index) {
      const no = index
      const list = this.testReviewList[no]
      getTestReviewTable(list).then((res) => {
        // console.log(res);
        this.testReviewTable = res
        this.openTable = true;
        this.title = "查看试卷复查表";
      })
    },
  }
};
</script>

<style scoped>
div /deep/ .el-scrollbar__wrap {
  overflow-x: hidden;
}
</style>